<?php
require_once(SERVER_FS_ROOT."/app/_inc/sdao/StructuredDataAccessObject.php");
require_once(SERVER_FS_ROOT."/app/_inc/mix.func.php");
require_once(SERVER_FS_ROOT."/app/util/imex/_inc/importExport.func.php");
/**
 * caricamento batch del file di release del meta-base
 */
function loadMetaBaseTxt(&$aImpTab) {
	global $objSDAO, $aMetaConPar;
	sxBatchOut("Caricamento file release nel meta-base");
	if (!is_object($objSDAO)) {$objSDAO = new SDAO($aMetaConPar);}
	$errMsg = '';
	$aConfTab = tabCompare($aImpTab);
	$aKeyVar = array();
	$aTot = array('ins'=>0,'mod'=>0,'del'=>0);
	foreach($aConfTab as $tabRef => $aTabRef) {
		foreach($aTabRef as $keyRef => $aTabImp) {
			foreach($aTabImp as $tab => $aKeys) {
				foreach($aKeys as $keyImp => $aVariaz) {
					//dbg_("tab=$tab - key=$keyImp - ".print_r($aVariaz,1));
					if (isset($aVariaz['op'])) {
						$aKeyVar[$tab][$keyImp] = $aVariaz['op'];
						$aTot[$aVariaz['op']] += 1;
					}
				}
			}
		}
	}
	//print_r($aKeyVar);
	$errMsg = tabImport($aImpTab, $aKeyVar);
	if ($errMsg != '') { 
		sxBatchOut($errMsg,true); 
	}
	sxBatchOut(_t('Elementi inseriti: %s, variati: %s, cancellati: %s',$aTot['ins'],$aTot['mod'],$aTot['del'])); 
	sxBatchOut(_t('File meta-base.txt caricato correttamente')); 
}

function sxBatchOut($mess,$abend=false) {
	if ($abend) {
		echo date('H:i:s')." - *********************************************************************\r\n";
		echo date('H:i:s')." - * ".$mess."\r\n";
		echo date('H:i:s')." - *********************************************************************\r\n";
		echo date('H:i:s')." - "._t("TERMINAZIONE ANOMALA !")."\r\n";
		exit(1);
	}
	echo date('H:i:s')." - ".$mess."\r\n";
}
?>
